<template>
  <div>
    <ul v-for="item in arr">
      <li>{{ item }}</li>
    </ul>
    <button @click="btn">走一走</button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      arr: ["帅哥", "美女", "程序员"],
    };
  },
  methods: {
    btn() {
      // 随机***************************************
      /* let arr1 = [...this.arr];
      for (let i = 0; i < arr1.length; i++) {
        let index = parseInt(Math.random() * arr1.length);
        // console.log(index);
        let temp = arr1[index];
        arr1[index] = arr1[i];
        arr1[i] = temp;
      }
      //   console.log(arr1);
      this.arr = arr1;
      console.log(this.arr);
 */
      //   随机*************************************
      let arr1 = this.arr;
      arr1.sort(function () {
        return Math.random() - 0.5;
      });
      this.arr = arr1;
      // 顺序***************************************
      /* this.arr.push(this.arr[0]);
      this.arr.splice(0, 1);
      console.log(arr); */
    },
  },
};
</script>

<style>
</style>